#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Christoph Lameter.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Uncomment this to turn on debug mode.
#export DEB_BUILD_OPTIONS="debug nostrip"

SSL=gnu
# uncomment the next line if you want openssl version
#SSL=ssl

export DH_OPTIONS=

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
DEBOP=--enable-debug
else
DEBOP=
endif

PACKAGE		:= $(shell dpkg-parsechangelog| 		\
			sed -n 's/^Source: \(.*\)$$/\1/p')
DSTDIR		:= $(CURDIR)/debian/$(PACKAGE)
BINDIR          := $(DSTDIR)/usr/bin
DOCDIR		:= $(DSTDIR)/usr/share/doc/$(PACKAGE)
SUBPACK		:= $(PACKAGE)-wrapper
SUBDIR		:= $(CURDIR)/debian/$(SUBPACK)

include /usr/share/quilt/quilt.make

configure: configure-$(SSL)
configure-gnu: configure-stamp
configure-ssl: configure-stamp-ssl

configure-stamp: patch
	cp -f debian/control-gnu debian/control
	dh_testdir
	# Add here commands to configure the package.
	dh_autotools-dev_updateconfig
	env cf_cv_SYSTEM_MAIL=/usr/sbin/sendmail \
	COMPRESS=/usr/bin/compress BZIP2=/bin/bzip2 UNZIP=/usr/bin/unzip \
	ZIP=/usr/bin/zip \
	LIBS="-lbsd" \
	./configure $(shell dpkg-buildflags --export=configure) --prefix=/usr --libexecdir=/usr/lib \
	--sysconfdir=/etc/lynx-cur --localstatedir=/var \
	--libdir=/etc/lynx-cur --enable-8bit-toupper --enable-externs \
	--enable-nsl-fork --enable-cgi-links --enable-exec-links \
	--enable-exec-scripts --enable-persistent-cookies --enable-nls \
	--enable-gzip-help --enable-prettysrc --enable-source-cache \
	--enable-cjk --enable-default-colors --enable-nested-tables \
	--enable-japanese-utf8 --enable-ipv6 \
        --enable-forms-options --enable-justify-elts --enable-partial \
        --enable-read-eta --enable-scrollbar --enable-syslog \
	--with-zlib --with-bzlib --without-included-gettext \
	--with-screen=ncursesw --enable-justify-elts \
	--with-gnutls=/usr --enable-persistent-cookies \
	${DEBOP}
#	--with-nss-compat --with-gnutls=/usr --enable-gnutls-compat 
#	--enable-color-style --enable-charset-choice --enable-font-switch

	touch configure-stamp

configure-stamp-ssl: patch
	sed -e "s/libgnutls-dev/libssl-dev/" debian/control-gnu > debian/control-ssl && \
	cp -f debian/control-ssl debian/control
	dh_testdir
	# Add here commands to configure the package.
	dh_autotools-dev_updateconfig
	env cf_cv_SYSTEM_MAIL=/usr/sbin/sendmail \
	COMPRESS=/usr/bin/compress BZIP2=/bin/bzip2 UNZIP=/usr/bin/unzip \
	ZIP=/usr/bin/zip \
	LIBS="-lbsd" \
	./configure $(shell dpkg-buildflags --export=configure) --prefix=/usr --libexecdir=/usr/lib \
	--sysconfdir=/etc/lynx-cur --localstatedir=/var \
	--libdir=/etc/lynx-cur --enable-8bit-toupper --enable-externs \
	--enable-nsl-fork --enable-cgi-links --enable-exec-links \
	--enable-exec-scripts --enable-persistent-cookies --enable-nls \
	--enable-gzip-help --enable-prettysrc --enable-source-cache \
	--enable-cjk --enable-default-colors --enable-nested-tables \
	--enable-japanese-utf8 --enable-ipv6 \
        --enable-forms-options --enable-justify-elts --enable-partial \
        --enable-read-eta --enable-scrollbar --enable-syslog \
	--with-zlib --with-bzlib --without-included-gettext \
	--with-screen=ncursesw --enable-justify-elts \
	--with-ssl --enable-persistent-cookies \
	${DEBOP}
#	--with-nss-compat --with-gnutls=/usr --enable-gnutls-compat 
#	--enable-color-style --enable-charset-choice --enable-font-switch

	touch configure-stamp-ssl

build: build-arch 
build-arch: configure build-stamp
build-indep: 
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp configure-stamp-ssl
	rm -f debian/control-ssl

	# Add here commands to clean up after the build process.
	[ ! -f makefile ] || $(MAKE) distclean
	#-rm -f intl/libintl.h

	dh_autotools-dev_restoreconfig
	dh_clean

#install: install-indep install-arch
install-indep:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -i

install-arch:
	dh_testdir
	dh_testroot
	dh_prep -s 
	dh_installdirs -s
#	chmod +x scripts/*.sh
	# Add here commands to install the package into debian/$(package).
	$(MAKE) install-full prefix=$(DSTDIR)/usr \
	libdir=$(DSTDIR)/etc/$(PACKAGE) \
	sysconfdir=$(DSTDIR)/etc/$(PACKAGE) docdir=$(DOCDIR) \
	helpdir=$(DOCDIR)/lynx_help \
	mandir=$(DSTDIR)/usr/share/man/man1
	cd $(DOCDIR) ; rm -rf samples test
	cd $(DOCDIR) ; rm -f COPYING lynx_help/COPYING lynx_help/COPYHEADER \
		CHANGES COPYING.asc COPYHEADER.asc
#	cd $(DSTDIR)/usr/share/man/man1 ; mv lynx.1 lynx.cur.1

# Build architecture-independent files here.
# for lynx-cur-wrapper
binary-indep: DH_OPTIONS=-i
binary-indep: install-indep
	dh_testdir
	dh_testroot
	dh_installdocs
#	dh_installman debian/lynx-cur.1
	dh_installchangelogs
	dh_install
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: DH_OPTIONS=-a
binary-arch: install-arch
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs debian/README.source
	dh_installmenu
	dh_installmime
	dh_installchangelogs CHANGES
	dh_install
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
